<?php
include("../share/config.php");
include "../share/lock.php";
if(!$conn)
{
  echo "连接失败了！！";
}


if($_SERVER["REQUEST_METHOD"] == "POST")
{

		// username and password sent from form 

		$myusername=$_POST['name']; 
		$mypassword=$_POST['password'];
		$sql="SELECT * FROM user WHERE student_id='$myusername'";
		$result=mysqli_query($conn,$sql);
		while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
			if ($row['password']==$mypassword){
				$_SESSION['login_user']=$myusername;
				$_SESSION['user_type']=$row['type'];//获取登录用户的身份类型
				$_SESSION['user_name']=$row['user_name'];
				if($_SESSION['user_type']==1)
				{
					header("location:../pages/admin/index.php");
				}
				elseif($_SESSION['user_type']==0)
				{
					header("location:../pages/stu/index.php");
				}
			}
			else
			{
				echo "<div class='alert alert-danger alert-dismissable'>";						
				echo "		<a href='../pages/login.php'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>";
				echo "			× ";
				echo "		</button></a>";
				echo "		<h4> ";
				echo "用户名或密码错误，请确认后重试。单击跳转回登录页面";
				echo "		</h4>";
				echo "	</div>";
			}
		}
				echo "<div class='alert alert-danger alert-dismissable'>";						
				echo "		<a href='../pages/login.php'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>";
				echo "			× ";
				echo "		</button></a>";
				echo "		<h4> ";
				echo "用户名或密码错误，请确认后重试。单击跳转回登录页面";
				echo "		</h4>";
				echo "	</div>";
				echo $login_session;
}
?>
